package jym.tan.movielibrary.component.renderer;

import java.awt.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import jym.tan.movielibrary.constant.ComponentConstant;

import org.apache.commons.lang.StringUtils;

public class MovieSearchResultTableCellRenderer extends DefaultTableCellRenderer {

	private static final long serialVersionUID = 61L;

	public MovieSearchResultTableCellRenderer() {
		super();
		setOpaque(true);
		setHorizontalAlignment(CENTER);
	}
	
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
		if(value != null) {
			if(value instanceof Date) {
				String date = new SimpleDateFormat("dd-MM-yyyy").format((Date) value);
				this.setText(date);
			} else {
				if(column == ComponentConstant.ColumnName.LANGUAGE.getOrder()) {
					this.setText(new Locale(value.toString()).getDisplayLanguage());
				} else if(column == ComponentConstant.ColumnName.CERTIFICATION.getOrder()) {
					this.setText(StringUtils.upperCase(value.toString()));
				} else {
					this.setText(value.toString());
				}
			}
		} else {
			this.setText("");
		}
		return this;
	}
}
